package com.start.client.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.client.app.entity.ClientDownRecordEntity;
import com.start.client.app.service.ClientDownRecordService;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.core.annotations.RegisterMenu;
import com.start.core.annotations.RegisterPermission;
import com.start.core.annotations.StartLog;
import com.start.security.annotations.DataPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * APP客户端管理
 *
 * @author gxl
 * @email ${email}
 * @date 2021-03-09 21:14:40
 */
@RestController
@RequestMapping("client/downRecord")
@RegisterMenu(value = "APP客户端下载记录", systemCode = "start:client:app:down", component = "views/start/client/appDown/index", path = "/client/appDown/index")
public class ClientDownRecordController {
    private static final String LOG_TITLE = "APP客户端下载记录";

    @Autowired
    private ClientDownRecordService service;

    /**
     * 列表
     */
    @GetMapping("/page")
    @DataPermission("app/app/list")
    public Result<?> list(Page<ClientDownRecordEntity> page, ClientDownRecordEntity entity) {
        QueryWrapper<ClientDownRecordEntity> queryWrapper = DataQueryConstructor.createEntity(entity);
        return Result.ok(service.page(page, queryWrapper));
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @StartLog(value = LOG_TITLE, action = "查询")
    @PreAuthorize("@pas.hasPermission('start:client:app:down:info')")
    @RegisterPermission(value = "start:client:app:down:info", name = "查看")
    public Result<?> info(@PathVariable("id") String id) {
        return Result.ok(service.getById(id));
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    @StartLog(value = LOG_TITLE, action = "添加")
    @PreAuthorize("@pas.hasPermission('start:client:app:down:add')")
    @RegisterPermission(value = "start:client:app:down:add", name = "添加")
    public Result<?> save(@RequestBody ClientDownRecordEntity app) {
        service.save(app);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/updateById")
    @StartLog(value = LOG_TITLE, action = "修改")
    @PreAuthorize("@pas.hasPermission('start:client:app:down:edit')")
    @RegisterPermission(value = "start:client:app:down:edit", name = "修改")
    public Result<?> update(@RequestBody ClientDownRecordEntity app) {
        service.updateById(app);
        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteById/{id}")
    @StartLog(value = LOG_TITLE, action = "删除")
    @PreAuthorize("@pas.hasPermission('start:client:app:down:delete')")
    @RegisterPermission(value = "start:client:app:down:delete", name = "删除")
    public Result<?> delete(@PathVariable("id") String id) {
        service.removeById(id);
        return Result.ok();
    }


}
